#ifndef __SLOTHTTPD_STAGES_SEND_FILE_HPP__
#define __SLOTHTTPD_STAGES_SEND_FILE_HPP__

#include <slothttpd/types.hpp>
#include <slothttpd/ref_counted.hpp>
#include <slothttpd/http/response.hpp>
#include <slothttpd/file.hpp>
#include <slothttpd/config/location/file_location.hpp>

namespace slothttpd {
namespace stage {

class send_headers;

class send_file;
typedef boost::intrusive_ptr<send_file> send_file_ptr;

class send_file :
        public ref_counted
{
public:
    send_file(connection_ptr conn, const char *path, config::file_location &conf);
    static void on_headers_sent(send_file_ptr s);
    
private:
    void post_send_wait();
    static void handle_send(send_file_ptr r, const boost::system::error_code &err);
    
    file_ptr responce_file;
    off_t offset_;
    send_headers *header_sender_;
};

}
}

#endif
